package com.service.affiliate.google.test;

import com.google.api.services.gan.model.CcOffer;
import com.google.api.services.gan.model.Event;
import com.google.api.services.gan.model.Events;
import com.google.api.oauth2.LocalServerReceiver;
import com.google.api.oauth2.OAuth2Native;
import com.google.api.oauth2.test.OAuth2ClientCredentials;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.List;

public class GanSample 
{
	
//	private static final String SCOPE = "https://www.googleapis.com/auth/gan.readonly";
//	
//	  public static void main(String[] args) throws Exception {
////	    OAuth2ClientCredentials.errorIfNotSpecified();
//	
//	    HttpTransport transport = new ApacheHttpTransport();
//	    JsonFactory jsonFactory = new JacksonFactory();
//	    HttpRequestInitializer init = OAuth2Native.authorize(
//	        transport, jsonFactory, new LocalServerReceiver(), null, "google-chrome",
//	        OAuth2ClientCredentials.getClientId(), OAuth2ClientCredentials.getClientSecret(), SCOPE);
//	
//	    System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//	    System.out.println("Credit Card Offers Api");
//	    System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//	    testCcOfferApi(transport, jsonFactory, init);
//	    System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//	    System.out.println("Event Api");
//	    System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//	    testEventApi(transport, jsonFactory, init);
//	  }
//	
//	  private static void testCcOfferApi(HttpTransport transport, JsonFactory jsonFactory,
//	                                     HttpRequestInitializer init) throws Exception {
//	    //Set up server
//	Gan server = new Gan(transport, init, jsonFactory);
//	
//	    //Set up request
//	    Gan.CcOffers.List request = server.ccOffers.list("112308");
//	
//	    //Execute request
//	    List<CcOffer> results = request.execute().getItems();
//	    if (results == null) {
//	      System.out.println("No Results Returned!");
//	    } else {
//	      for (CcOffer c : results) {
//	        System.out.println(c);
//	      }
//	    }
//	  }
//	
//	  private static void testEventApi(HttpTransport transport, JsonFactory jsonFactory,
//	                                   HttpRequestInitializer init) throws Exception{
//	    //Set up server
//	    Gan server = new Gan(transport, init, jsonFactory);
//	
//	    //Set up request
//	    Gan.Events.List request = server.events.list("publishers", "1002");
//	    request.setEventDateMin("2011-08-11T04:11:42.000Z");
//	
//	    //Execute request
//	    List<Event> results = request.execute().getItems();
//	    System.out.println("Not filtered: ");
//	    if (results == null) {
//	      System.out.println("No Results Returned!");
//	    } else {
//	      for (Event e : results) {
//	        System.out.println("Advertiser ID: "  e.getAdvertiserId()  " Order ID: "  e.getOrderId()
//	                            " Event Date: "  e.getEventDate());
//	      }
//	    }
//	
//	    //Set up request
//	    request = server.events.list("publishers", "1002");
//	    request.setOrderId("2416288^2416508"); //Only these two events should appear
//	    request.setEventDateMin("2011-08-11T04:11:42.000Z");
//	
//	    //Execute request
//	    results = request.execute().getItems();
//	    System.out.println("Filtered on order ID: ");
//	    if (results == null) {
//	      System.out.println("No Results Returned!");
//	    } else {
//	      for (Event e : results) {
//	        System.out.println("Advertiser ID: "  e.getAdvertiserId()  " Order ID: "  e.getOrderId()
//	                            " Event Date: "  e.getEventDate());
//	      }
//	    }
//	  }
//	}
}
